Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JarReader #16

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open

Add JarReader #16

wants to merge 8 commits into from

Conversation

jackassmc
Copy link

This PR adds support for reading an empty mapping (source only) from a jar file. The result can be written out as Enigma and Tiny v2, Tiny v1 skips everything without a destination so it can't be used.

@@ -69,6 +70,8 @@ public static MappingFormat detectFormat(Reader reader) throws IOException {
case "MD:":
case "FD:":
return MappingFormat.SRG;
case "PK\u0003":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct when the jar is read as if it's utf-8?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This correctly identifies jar files when using something like

MappingReader.read(Path.of("minecraft-1.18.2-client.jar"), mappingTree);


@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
buffer = processFile(file, buffer, visitor);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In jars, some directories aren't valid package names, like ones with -, also the META_INF and the version-specific class files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processFile ignores any files not ending with ".jar" or ".class", is that enough to skip non valid files?

Copy link

@liach liach Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't handle say classes in doc-files or multi-release classes in META-INF. Checking and skipping invalid directories may be needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all classes be processed regardless of the directory they're in? processClass only uses the file content, not the file name or directory.

Copy link

@liach liach Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this isn't determinate for Multi-release jars, also doc files etc should be ignored

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, are there any directories besides "META-INF" and "doc-files" that need to be filtered out?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend skipping any class in any folder with - in name, as those are invalid java package names. However, I don't know how you want to deal with nested jars, and you might still consider jars in those directories.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It now skips any classes in folders with names containing "-". Jars are not affected by this but they should probably be skipped if they are in "doc-files" folders.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jars in "doc-files" folders are now skipped.

@sfPlayer1
Copy link
Contributor

I wanted to do this in a more layered fashion with mapping packaging as its own encompassing facility, not merged with mapping formats

@jackassmc
Copy link
Author

I wanted to do this in a more layered fashion with mapping packaging as its own encompassing facility, not merged with mapping formats

Could you elaborate on this please so I can see if this is something I might be able to implement?

@jackassmc
Copy link
Author

JarReader now uses ZipFile which allows it to read zip files that contain extra data at the beginning of the file. This makes it possible to read the old Minecraft windows_server executables.

Nested jars are ignored at the moment

public static void read(Path path, MappingVisitor mappingVisitor) throws IOException {
AnalyzingVisitor analyzingVisitor = new AnalyzingVisitor(mappingVisitor);

ZipFile zipFile = new ZipFile(path.toFile());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably use a jar file system instead,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it's really convenient to pass a ZipEntry to ClassReader, what's the benefit of a jar file system?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For it's more modern, and you can skip invalid directory with its children (like in a DirectoryStream) than having to step into it like when you are iterating with a zip file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants